]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
extension-tool: Use enable/disable D-Bus API if possible
authorFlorian Müllner <fmuellner@gnome.org>
Tue, 23 Jul 2019 23:37:09 +0000 (23:37 +0000)
committerFlorian Müllner <fmuellner@gnome.org>
Sun, 5 Apr 2020 11:42:50 +0000 (13:42 +0200)
Commit 4589da957 added D-Bus API for enabling/disabling extensions,
use that if possible to provide better feedback and not clutter the
settings with non-existent UUIDs.

The old code path is preserved as fallback to keep the commands
working from outside a running shell session.

https://gitlab.gnome.org/GNOME/gnome-shell/issues/2391

subprojects/extensions-tool/src/command-disable.c
subprojects/extensions-tool/src/command-enable.c

index 116f6699cb30f058c2ee29eb8afa137ffa9e3d05..93c316bf7864baa0b3af8151f35171e1f51c2dd5 100644 (file)
 #include "config.h"
 
 static gboolean
-disable_extension (const char *uuid)
+disable_extension_dbus (GDBusProxy *proxy,
+                        const char *uuid)
+{
+  g_autoptr (GVariant) response = NULL;
+  g_autoptr (GError) error = NULL;
+  gboolean success = FALSE;
+
+  response = g_dbus_proxy_call_sync (proxy,
+                                     "DisableExtension",
+                                     g_variant_new ("(s)", uuid),
+                                     0,
+                                     -1,
+                                     NULL,
+                                     &error);
+
+  if (response == NULL)
+    {
+      g_printerr (_("Failed to connect to GNOME Shell\n"));
+      return FALSE;
+    }
+
+  g_variant_get (response, "(b)", &success);
+
+  if (!success)
+    g_printerr (_("Extension “%s” does not exist\n"), uuid);
+
+  return success;
+}
+
+static gboolean
+disable_extension_gsettings (const char *uuid)
 {
   g_autoptr(GSettings) settings = get_shell_settings ();
 
@@ -37,6 +67,20 @@ disable_extension (const char *uuid)
          settings_list_add (settings, "disabled-extensions", uuid);
 }
 
+static gboolean
+disable_extension (const char *uuid)
+{
+  g_autoptr (GDBusProxy) proxy = NULL;
+  g_autoptr (GError) error = NULL;
+
+  proxy = get_shell_proxy (&error);
+
+  if (proxy != NULL)
+    return disable_extension_dbus (proxy, uuid);
+  else
+    return disable_extension_gsettings (uuid);
+}
+
 int
 handle_disable (int argc, char *argv[], gboolean do_help)
 {
index 786e4510956ec90df173b693b6bed5ca96ec57fd..6ae3a83513e434dd01a7b30b14e8f5864118d244 100644 (file)
 #include "config.h"
 
 static gboolean
-enable_extension (const char *uuid)
+enable_extension_dbus (GDBusProxy *proxy,
+                       const char *uuid)
+{
+  g_autoptr (GVariant) response = NULL;
+  g_autoptr (GError) error = NULL;
+  gboolean success = FALSE;
+
+  response = g_dbus_proxy_call_sync (proxy,
+                                     "EnableExtension",
+                                     g_variant_new ("(s)", uuid),
+                                     0,
+                                     -1,
+                                     NULL,
+                                     &error);
+
+  if (response == NULL)
+    {
+      g_printerr (_("Failed to connect to GNOME Shell\n"));
+      return FALSE;
+    }
+
+  g_variant_get (response, "(b)", &success);
+
+  if (!success)
+    g_printerr (_("Extension “%s” does not exist\n"), uuid);
+
+  return success;
+}
+
+static gboolean
+enable_extension_gsettings (const char *uuid)
 {
   g_autoptr(GSettings) settings = get_shell_settings ();
 
@@ -37,6 +67,20 @@ enable_extension (const char *uuid)
          settings_list_remove (settings, "disabled-extensions", uuid);
 }
 
+static gboolean
+enable_extension (const char *uuid)
+{
+  g_autoptr (GDBusProxy) proxy = NULL;
+  g_autoptr (GError) error = NULL;
+
+  proxy = get_shell_proxy (&error);
+
+  if (proxy != NULL)
+    return enable_extension_dbus (proxy, uuid);
+  else
+    return enable_extension_gsettings (uuid);
+}
+
 int
 handle_enable (int argc, char *argv[], gboolean do_help)
 {